﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Solidi
{
	public class DependencyRoot
	{
		private Dependency _dependency;
		private IEnumerable<DependencyChild> _children;

		public DependencyRoot(Dependency dependency, IEnumerable<DependencyChild> children)
		{
			_dependency = dependency;
			_children = children;
		}

		public DependencyDisposal Release(object instance)
		{
			return _dependency.Release(instance);
		}

		public void Dispose(object instance)
		{
			IDisposable disposable = instance as IDisposable;

			if (disposable != null)
			{
				disposable.Dispose();
			}

			foreach (DependencyChild child in _children)
			{
				child.Dispose();
			}
		}
	}
}
